/**
 * @file Driver_Button.c
 * @brief 
 * @author 2bam 
 * @version 1.0
 * @date 2024-12-09
 * @copyright Copyright (c) 2024  NULL
 * 
 * @change log:
 * Date           Version Author   Describe
 * 2024-12-09     1.0     2bam     first version
 */


/* Includes -------------------------------------------------------------------*/
#include "config.h"

#include "../../Component/MultiButton/multi_button.h"
/* define ---------------------------------------------------------------------*/

/* typedef --------------------------------------------------------------------*/

/* variables ------------------------------------------------------------------*/
struct Button button0;
/* Private function prototypes ------------------------------------------------*/

/**
 * @brief 按钮单击事件
 * @param  btn         My Param doc
 * @date 2024-12-09
 * @author 2bam 
 */
void Callback_SINGLE_CLICK_Handler(void* btn)
{
    OLED_PrintASCIIString(0,24,"Single Click.",&afont8x6,OLED_COLOR_NORMAL);
    OLED_ShowFrame();
}

/**
 * @brief 
 * @param  btn         My Param doc
 * @date 2024-12-09
 * @author 2bam 
 */
void Callback_DOUBLE_CLICK_Handler(void* btn)
{
    OLED_PrintASCIIString(0,24,"Double Click.",&afont8x6,OLED_COLOR_NORMAL);
    OLED_ShowFrame();
}

/**
 * @brief 
 * @return uint8_t 
 * @date 2024-12-09
 * @author 2bam 
 */
uint8_t read_button0_GPIO(void)
{
    return (uint8_t)HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin);
}


/**
 * @brief 
 * @date 2024-12-09
 * @author 2bam 
 */
void buttons_register(void)
{
    button_init(&button0, read_button0_GPIO, 0);
    button_attach(&button0, SINGLE_CLICK, Callback_SINGLE_CLICK_Handler);
    button_attach(&button0, DOUBLE_CLICK, Callback_DOUBLE_CLICK_Handler);
    button_start(&button0);
}

